/**
  * 基类  模块
  * @class Bridge
  */
class Bridge{
  constructor (mod) {
    if ((mod != '' && mod != null && mod != 'undefined'))
    {
      this.Ctrl = mod;
    }
    else
		this.Ctrl = null;
  }
  
    /**
   *	获得打印当前电脑打印机信息
   * @param  {String} ipSegment  IP扫描的地址段，最多5个。举例：“192.168.3.|192.168.2.|192.168.1.“
   * @returns {Promise<String>}
   * @return {String} usb设备列表 举例：vid_6868&pid_0600|vid_6800&pid_0655
   */
   getUsbPrintDeviceList(){
	   return new Promise((resolve, reject) => {
		this.Ctrl.GetUsbPrintDeviceList((ret) => {
         resolve(ret);
      });
   });
   }
   
  
  /**
   *	设置IP地址段
   * @param  {String} ipSegment  IP扫描的地址段，最多5个。举例：“192.168.3.|192.168.2.|192.168.1.“
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
   setIpSegment(ipSegment){
	   return new Promise((resolve, reject) => {
		this.Ctrl.SetIpSegment(ipSegment,(ret) => {
        if (ret == 0) {
          resolve("Success");
        }
		else
			resolve("Fail");
      });
   });
   }
   
     /**
   *	获取设置的IP扫描的地址段对应IP是否可以PING通
   * @param  {String} ipSegment  IP扫描的地址段，最多5个。举例：“192.168.3.|192.168.2.|192.168.1.“
   * @returns {Promise<String>}
   * @return {String} "192.168.3.,1:0,2:0,3:1,4:0|192.168.2.,1:0,2:0,3:1,4:0"-成功 <br> Fail-失败
   */
   getIpSegmentPingResult(){
	   return new Promise((resolve, reject) => {
		this.Ctrl.GetIpSegmentPingResult((ret) => {
		resolve(ret);
	});
   });
   }
   
  /**
   * 打开USB打印机
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
  openPrint(strVidPid) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.PrintOpen(strVidPid,(ret) => {
		resolve(ret);
	});
	});
  }
    /**
   * 关闭USB打印机
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
  closePrint(strVidPid) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.PrintClose(strVidPid, (ret) => {
		resolve(ret);
	});
	});
  }
  
    /**
   * 字符串打印
   * @param {String} strVidPid vid和pid字符串，比如‘vid_0483&pid_070b’
   * @param {String} strData 打印的字符串数据
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
  printData(strVidPid,strData) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.PrintData(strVidPid,strData, (ret) => {
		resolve(ret);
	});
	});
  }
  
   /**
   * USB打印机16进制格式字符串打印
   * @param {String} strVidPid vid和pid字符串，比如‘vid_0483&pid_070b’
   * @param {String} strCMD 16进制字符串，每个字符中间用‘,'分割，比如‘28,38,27’
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
  printCmd(strVidPid,strCMD) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.PrintCmd(strVidPid,strCMD, (ret) => {
		resolve(ret);
	});
	});
  }
  
  /**
   * 网络打印机16进制格式字符串打印
   * @param {String} strIp IP地址
   * @param {String} strPort 端口
   * @param {String} strCMD 16进制字符串，每个字符中间用‘,'分割，比如‘28,38,27’
   * @returns {Promise<String>}
   * @return {String} Success-成功 <br> Fail-失败
   */
  printTcp(strIp,strPort,strCMD) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.PrintTcp(strIp,strPort,strCMD, (ret) => {
		resolve(ret);
	});
	});
  }
   /**
   * 获取mac地址
   * @returns {Promise<String>}
   * @return {String} Mac地址-成功 <br> 空字符串-失败
   */
  getMac () {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.GetHostMacAddress((ret) => {
		resolve(ret);
		});
	});
  }
  
    /**
   * 获取指定文件名的版本号
   * @param {String} name 文件名称，比如“MiniBrowser.exe”
   * @returns {Promise<String>}
   * @return {String} 版本号-成功 <br> 空字符串-失败
   */
  getVer (fileName) {
    return new Promise((resolve, reject) => {
		var ret = this.Ctrl.GetFileVertion(fileName, (ret) => {
		resolve(ret);
		});
	});
  }
}